using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Models;
using IDAL;

namespace DAL
{
    public class ExcelService:IExcelService
    {
        private ITAMContext dbContext = null;
        public ExcelService(ITAMContext context)
        {
            this.dbContext = context;
        }

        public bool ImportDevice(List<DeviceRecord> records)
        {
            if(records.Count==0)
            {
                return false;
            }
            using var transaction = dbContext.Database.BeginTransaction();
            try
            {
                foreach(var item in records)
                {
                    dbContext.Entry(item).State = EntityState.Added;
                    dbContext.SaveChanges();
                }
                transaction.Commit();
                return true;
            }
            catch(Exception)
            {
                transaction.Rollback();
                return false;
            }
        }

        public byte[] ExportDevice(List<DeviceRecord> records,string[] tableTitle)
        {
            byte[] buffer = new byte[1024 * 5];
            return buffer;
        }
    }
}